<?php
// +----------------------------------------------------------------------
// | Jqcms [ Avenue to Jane ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://jqcms.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: hyacinth <845077398@qq.com>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Common\Controller\BaseController;

class LinkController extends BaseController {
    
    public function index(){
       
        $link = M('Link');
        $where = "";
        $count = $link->where($where)->count();
        $p = getpage($count,10);
        $list = $link->field(true)->where($where)->order('sort desc,id desc')->limit($p->firstRow, $p->listRows)->select();
        $this->assign('list', $list);
        $this->assign('page', $p->show());
        $this->display();
        
    }

    public function create(){
        
        $link = D('Link');
        if(IS_POST){
            
            if($link->create()){
                $link->add();
                $this->success('添加成功!','index');
            }else{
                $this->error($link->getError());
            }
                
        }else{
            $this->display();
        }
        
    }
    
    public function edit($id){
        
        $link = D('Link');
        if (IS_POST) {
            
            if($link->create()){
                $link->save();
                $this->success('编辑成功!','index');
            }else{
                $this->error($link->getError()); 
            }
            
        }else {
            $data = $link->find($id);
            $this->assign('data',$data);
            $this->display();
        }
        
    }
    
    public function del($id){
        
        $link = M('Link');
        $del = $link->delete($id);
        
        if($del !==0 && $del !==false){
            $this->success('删除成功!');
        }else {
            $this->error('删除失败!');
        }
         
    }
    
  
    
}